package com.zbkj.crmeb.store.service.impl;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.PageParamRequest;
import com.github.pagehelper.PageHelper;
import com.zbkj.crmeb.store.dao.StoreProductDescriptionDao;
import com.zbkj.crmeb.store.model.StoreProductDescription;
import com.zbkj.crmeb.store.request.StoreProductDescriptionSearchRequest;
import com.zbkj.crmeb.store.service.StoreProductDescriptionService;

/**
 * @author Mr.Zhang
 * @description StoreProductDescriptionServiceImpl 接口实现
 * @date 2020-05-27
 */
@Service
public class StoreProductDescriptionServiceImpl extends ServiceImpl<StoreProductDescriptionDao, StoreProductDescription> implements StoreProductDescriptionService {

    @Resource
    private StoreProductDescriptionDao dao;


    /**
     * 列表
     *
     * @param request          请求参数
     * @param pageParamRequest 分页类参数
     * @return List<StoreProductDescription>
     * @author Mr.Zhang
     * @since 2020-05-27
     */
    @Override
    public List<StoreProductDescription> getList(StoreProductDescriptionSearchRequest request, PageParamRequest pageParamRequest) {
        PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());

        //带 StoreProductDescription 类的多条件查询
        LambdaQueryWrapper<StoreProductDescription> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        StoreProductDescription model = new StoreProductDescription();
        BeanUtils.copyProperties(request, model);
        lambdaQueryWrapper.setEntity(model);
        return dao.selectList(lambdaQueryWrapper);
    }

    @Override
    public void deleteByProductId(int productId) {
        LambdaQueryWrapper<StoreProductDescription> lmq = new LambdaQueryWrapper<>();
        lmq.eq(StoreProductDescription::getProductId, productId);
        dao.delete(lmq);
    }

    /**
     * 查询商品desc
     *
     * @param productIds
     * @return
     */
    @Override
    public Map<Integer, String> getProductDescMap(List<Integer> productIds) {
        List<StoreProductDescription> list = dao.selectList(Wrappers.<StoreProductDescription>lambdaQuery().in(StoreProductDescription::getProductId, productIds));
        return list.stream().collect(Collectors.toMap(StoreProductDescription::getProductId, StoreProductDescription::getDescription, (v1, v2) -> v1));
    }
    /**
     * 更新desc
     *
     * @param id
     * @param storeInfo
     * @return
     */
	/*@Override
	public boolean updateStoreProductDescription(Integer id, String storeInfo) {
	    if (null == storeInfo) {
	        return false;
	    }
	    LambdaUpdateWrapper<StoreProductDescription> wrapper = new LambdaUpdateWrapper();
	    wrapper.eq(StoreProductDescription::getProductId, id);
	    wrapper.set(StoreProductDescription::getDescription, storeInfo);
	    return this.update(wrapper);
	}*/
}

